#ifndef __HALUART1_H
#define __HALUART1_H

#include <string.h>
#include <stdbool.h>

#include "main.h"

#include "usart.h"


#ifndef	U1_Rx_Len
	#define U1_Rx_Len 255
#endif 



#pragma pack(1)


typedef struct  
{ 
	uint16_t dataSize;
	uint8_t  dataBuf[U1_Rx_Len];
}Uart1_RxBuffer_t; 


typedef struct {
    uint8_t address;      // 从机地址
    uint8_t function_code; // 功能码
    uint16_t coil_address; // 线圈地址
    uint16_t coil_status;  // 线圈状态：0xFF00为ON, 0x0000为OFF
    uint16_t crc;          // CRC校验码
} Modbus05Request;

typedef struct {
    uint8_t address;      // 从机地址
    uint8_t function_code; // 功能码
    uint16_t coil_address; // 线圈地址
    uint16_t coil_status;  // 线圈状态
    uint16_t crc;          // CRC校验码
} Modbus05Response;


typedef struct {
    uint8_t address;          // 从机地址
    uint8_t function_code;    // 功能码
    uint16_t starting_address; // 起始地址
    uint16_t quantity_of_coils; // 线圈数量
    uint8_t byte_count;        // 字节数
    uint8_t coil_data[256];    // 线圈数据（最多支持256个线圈）
    uint16_t crc;              // CRC校验码
} Modbus0FRequest;

typedef struct {
    uint8_t address;          // 从机地址
    uint8_t function_code;    // 功能码
    uint16_t starting_address; // 起始地址
    uint16_t quantity_of_coils; // 线圈数量
    uint16_t crc;              // CRC校验码
} Modbus0FResponse;
#pragma pack()






void HAL_Uart1_Init(void);
bool HAL_Uart1_Send(uint8_t* pBuf, uint16_t len);
void HAL_Uart1_IDLE(void);
__weak void HAL_Uart1_Callback(uint8_t* pBuf, uint16_t len);


void HAL_Uart3_Init(void);
bool HAL_Uart3_Send(uint8_t* pBuf, uint16_t len);
void HAL_Uart3_IDLE(void);
__weak void HAL_Uart3_Callback(uint8_t* pBuf, uint16_t len);


#endif






























